package com.touni.datastructure;

/**
 * @ClassName : NodeQueue
 * @Description :
 * @Author : lwq
 * @Date: 2021-04-23 15:49
 */
public class NodeQueue<T> {

    private Node<T> head;
    private Node<T> tail;

    class Node<T> {
        T value;
        Node<T> next;
    }

    public boolean add(T value){
        Node<T> node = new Node<T>();
        if (tail != null){
            tail.next = node;
        }
        node.value = value;
        if (head == null){
            head = node;
        }
        tail = node;
        return Boolean.TRUE;
    }

    public T poll(){
        if (head == null){
            throw new RuntimeException("queue is empty");
        }
        T value = head.value;
        head = head.next;
        return value;

    }

    public T peek(){
        if (head == null){
            throw new RuntimeException("queue is empty");
        }
        return head.value;
    }
}
